//
//  TestDataInputer.m
//  UnitTests
//
//  Created by Jiang on 2018/10/22.
//  Copyright © 2018 jiang. All rights reserved.
//

#import "DataInputer.h"
#import "NormalTalk.h"
@implementation DataInputer
+ (NSArray <NormalTalk *>*)normalTalksWithPath:(NSString *)path{
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return [self normalTalksWithString:str];
}
+ (NSArray <NormalTalk *>*)normalTalksWithString:(NSString *)string{
    NSArray *contents = [string componentsSeparatedByString:@"\n"];
    NSMutableArray *talks = [NSMutableArray array];
    for (NSString* content in contents){
        NormalTalk *atalk = [[NormalTalk alloc] initWitContent:content tag:[contents indexOfObject:content]];
        if ([atalk verifyContent]) {
            [talks addObject:atalk];
        }
    }
    return [talks copy];
}
#pragma mark - TEST
+ (NSArray<NormalTalk *> *)talksWithBundleFileName:(NSString *)filename{
    NSString *path = [[NSBundle bundleForClass:self] pathForResource:filename ofType:@"txt"];
    return [self normalTalksWithPath:path];
}
+ (NSArray<NormalTalk *> *)exampleTestData{
    return [self talksWithBundleFileName:@"ExampleTestData"];
}
+ (NSArray<NormalTalk *> *)littleTestData{
    return [self normalTalksWithString:@"\
            1 5min\n\
            2 5min\n\
            3 10min\n\
            4 2min\n\
            5 3min"];
}
+ (NSArray<NormalTalk *> *)normalTestData{
    return [self normalTalksWithString:@"\
            1 10min\n\
            2 20min\n\
            3 30min\n\
            4 40min\n\
            5 50min\n\
            6 60min\n\
            7 70min\n"];
}
+ (NSArray<NormalTalk *> *)hasWrongTestData{
    return [self normalTalksWithString:@"\
            1 10min\n\
            2 20min\n\
            3 30min\n\
            4 40min\n\
            5 50min\n\
            6 60min\n\
            769min\n\
            lala\n\
            sssss\n"];
}
@end
